package com.cate.controller.admin;

import com.cate.base.BasePageVO;
import com.cate.pojo.dto.OrdersCancelDTO;
import com.cate.pojo.dto.OrdersConfirmDTO;
import com.cate.pojo.dto.OrdersPageQueryDTO;
import com.cate.pojo.dto.OrdersRejectionDTO;
import com.cate.pojo.entity.Orders;
import com.cate.pojo.vo.OrderStatisticsVO;
import com.cate.pojo.vo.OrderVO;
import com.cate.result.RestResponse;
import com.cate.service.OrdersService;
import com.cate.utils.ResultUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @CreateTime: 2023/7/31
 * @Author: <==lhd==>
 * @Description:
 */

@RestController
@RequestMapping("/admin/order")
@Slf4j
@Api(tags = "订单管理")
public class OrdersController {

    @Autowired
    private OrdersService ordersService;

    @PutMapping("/rejection")
    @ApiOperation("商家拒单")
    public RestResponse rejectOrder(@RequestBody OrdersRejectionDTO ordersRejectionDTO){
        ordersService.rejectOrder(ordersRejectionDTO);
        return ResultUtil.success("");
    }
    @PutMapping("/cancel")
    @ApiOperation("取消订单")
    public RestResponse cancelOrder(@RequestBody OrdersCancelDTO ordersCancelDTO){
        ordersService.cancelOrder(ordersCancelDTO);
        return  ResultUtil.success("");
    }

    @PutMapping("/confirm")
    @ApiOperation("商家接单")
    public RestResponse confirmOrder(@RequestBody OrdersConfirmDTO ordersConfirmDTO){
        ordersService.confirmOrder(ordersConfirmDTO);
        return ResultUtil.success("");
    }

    @PutMapping("/complete/{id}")
    @ApiOperation("完成订单")
    public RestResponse completeOrder(@PathVariable("id") Long orderId){
        ordersService.completeOrder(orderId);
        return ResultUtil.success("");
    }

    @PutMapping("/delivery/{id}")
    @ApiOperation("派送订单")
    public RestResponse deliveryOrder(@PathVariable("id") Long orderId){
        ordersService.deliveryOrder(orderId);
        return ResultUtil.success(null);
    }

    @GetMapping("/details/{id}")
    @ApiOperation("查询订单详情")
    public RestResponse getOrdersById(@PathVariable("id") Long id){
        final OrderVO orderVO = ordersService.getOrdersById(id);
        return ResultUtil.success(orderVO);
    }

    @GetMapping("/statistics")
    @ApiOperation("订单数量统计")
    public RestResponse getOrderStatistics(){
        final OrderStatisticsVO orderStatistics = ordersService.getOrderStatistics();
        return ResultUtil.success(orderStatistics);
    }

    @GetMapping("/conditionSearch")
    @ApiOperation("分页订单搜索")
    public RestResponse conditionSearch(OrdersPageQueryDTO ordersPageQueryDTO){
        final BasePageVO<Orders> basePageVO = ordersService.pageQuery(ordersPageQueryDTO);
        return ResultUtil.success(basePageVO);
    }

}
